<template>
    <h4>简易输入</h4>
    <div class="input">
        <t-textarea class="editor" v-model="value3" placeholder="请输入文案，高度可自适应，最小3行，最大5行" name="description"
            :autosize="{ minRows: 3, maxRows: 20 }" />
        <div class="toolbar">
            <div class="left">
                <t-icon name="play-circle" class="btn" />
                <t-icon name="play-circle" class="btn" />
                <t-icon name="play-circle" class="btn" />
                <t-icon name="play-circle" class="btn" />
            </div>

            <div class="right">
                <t-icon name="play-circle" class="btn" />
            </div>
        </div>
    </div>
    <h4>富文本</h4>
    <div class="input1" style="height: 300px;">
        <QuillEditor toolbar="#my-toolbar"></QuillEditor>
        <div id="my-toolbar">
            <!-- Add buttons as you would before -->
            <button class="ql-bold"></button>
            <button class="ql-italic"></button>
            <button id="custom-button">app</button>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css';

const value3 = ref('');

const onChange = (value: string, e: Event) => {
    console.log('onChange：', value, e);
    value3.value = value;
};
</script>

<style lang="scss" scoped>
$toolbar-height: 40px;
$editor-width: 700px;
$min-rows: 3;
$line-height: 24px; // 假设每行高度为24px
$padding: 16px; // textarea的padding

.input {
    background-color: #f5f5f5;
    width: $editor-width;
    min-height: calc(#{$min-rows * $line-height} + #{$toolbar-height});
    margin: 40px auto;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #e0e0e0;
}

.editor {
    width: 100%;

    // 隐藏外边框的优化版本
    :deep(.t-textarea) {
        border: none !important;
        outline: none !important;
        box-shadow: none !important;
        border-radius: 0;
    }

    :deep(.t-textarea__inner) {
        border: none !important;
        outline: none !important;
        box-shadow: none !important;
        resize: none; // 禁止手动调整大小
    }

    // 移除聚焦时的所有边框和阴影
    :deep(.t-textarea--focused) {
        border: none !important;
        box-shadow: none !important;
    }
}

.toolbar {
    display: flex;
    align-items: center;
    height: $toolbar-height;
    background-color: #fff;
    border-top: 1px solid #e0e0e0;
    padding: 0 12px;
    justify-content: space-between;

    .btn {
        color: #666;
        font-size: 20px;
        cursor: pointer;
        margin-right: 12px;
        transition: color 0.2s ease;

        &:hover {
            color: #0066cc;
        }
    }
}

// 响应式优化
@media (max-width: 768px) {
    .input {
        width: 95%;
        margin: 20px auto;
    }

    .toolbar {
        justify-content: center;
    }
}
</style>